package com.dapeis.web.wx.utils;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.ag.core.IFreemarkerMarker;

@Component("wxTagUtils")
public class WXTagUtils extends IFreemarkerMarker {
	
	private final static long minute = 60 * 1000;// 1分钟 毫秒数
	private final static long hour = 60 * minute;// 1小时
	private final static long day = 24 * hour;// 1天
	private final static long month = 31 * day;// 月
	private final static long year = 12 * month;// 年

	private final static Map<Integer, String> orderItemProgressMap = new HashMap<Integer, String>();
	static {
		orderItemProgressMap.put(0, "未支付");
		orderItemProgressMap.put(1, "已支付");
		orderItemProgressMap.put(2, "已使用");
		orderItemProgressMap.put(3, "已评价");
	}
	
	public WXTagUtils() {
	}

	/**
	 * 供freemark页面使用
	 * Unix时间戳转换成 xx之前
	 * @param dateTimeInSecond unix时间戳，单位秒
	 * @return
	 */
	public static String unixTime2ago(Long dateTimeInSecond) {
		if(null == dateTimeInSecond){
			return "不知过去了多久";
		}
		
		long diff = System.currentTimeMillis() - dateTimeInSecond * 1000;
		long r = 0;
		if (diff > year) {
			r = (diff / year);
			return r + "年前";
		}
		if (diff > month) {
			r = (diff / month);
			return r + "个月前";
		}
		if (diff > day) {
			r = (diff / day);
			return r + "天前";
		}
		if (diff > hour) {
			r = (diff / hour);
			return r + "个小时前";
		}
		if (diff > minute) {
			r = (diff / minute);
			return r + "分钟前";
		}
		return "刚刚";
	}
	
	public static String orderItemProgressTxt(Integer currProgress) {
		if(null == currProgress){
			return "状态未知";
		}
		return orderItemProgressMap.get(currProgress);
	}
}
